﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace StudioLib
{
    public static class Log
    {
        enum LogEntryType
        {
            INF,
            WRN,
            ERR
        }

        struct LogEntry
        {
            public string message;
            public DateTime timeStamp;
            public LogEntryType type;
        }

        static List<LogEntry> log = new List<LogEntry>();
        
        private static void LogAny(String message, LogEntryType type)
        {
            LogEntry entry = new LogEntry();
            entry.message = message;
            entry.timeStamp = DateTime.Now;
            entry.type = type;

            log.Add(entry);

            DumpToFile("log.txt");
        }

        public static void LogError(String message)
        {
            LogAny(message, LogEntryType.ERR);
        }
        
        public static void LogInfo(String message)
        {
            LogAny(message, LogEntryType.INF);
        }

        public static void LogWarning(String message)
        {
            LogAny(message, LogEntryType.WRN);
        }

        public static void DumpToFile(String file)
        {
            
            StreamWriter dump = File.CreateText(file);

            foreach (LogEntry le in log)
            {
                dump.WriteLine("[{0}] {1} : {2}", le.type, le.timeStamp, le.message);
            }

            
            dump.Close();
        }
    }
}
